package com.ch.demo;

import java.util.*;
import java.util.stream.Collectors;

public class Demo1 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("banana");
        list.add("apple");
        list.add("purple");
        list.add("momo");
        list.add("orange");
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return ((String)o1).length() - ((String)o2).length();
            }
        });

        System.out.println(list);
        List<String> list1 = list.stream().filter(s -> s.startsWith("a")).collect(Collectors.toList());
        System.out.println(list1);
        List<Integer> list2 = list.stream().map(s -> s.length()).collect(Collectors.toList());
        System.out.println(list2);

        List<Integer> list3 = Arrays.asList(1,2,3,4,5);
        int sum = list3.stream().reduce(0,(a,b) -> a + b);
        System.out.println(sum);
    }
}
